package com.dev;

import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;

import com.dev.common.util.GeneratedClassUtils;
import com.dev.view.tab1.FragmentTab1;
import com.dev.view.tab2.FragmentTab2;
import com.dev.view.tab3.FragmentTab3;
import com.dev.view.tab4.FragmentTab4;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;


@EActivity(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {

    private final static String TAB1 = "tab_1";
    private final static String TAB2 = "tab_2";
    private final static String TAB3 = "tab_3";
    private final static String TAB4 = "tab_4";

    @ViewById(android.R.id.tabhost)
    FragmentTabHost tabHost;

    @AfterViews
    public void initView() {
        tabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
//        tabHost.getTabWidget().setDividerDrawable(null); // 去掉分割线
//        tabHost.setBackgroundResource(R.mipmap.ic_launcher);
        tabHost.addTab(createSpec(TAB1, getString(R.string.tab_1), getString(R.string.icon_font_tab_customer)), GeneratedClassUtils.get(FragmentTab1.class), null);
        tabHost.addTab(createSpec(TAB2, getString(R.string.tab_2), getString(R.string.icon_font_tab_house)), GeneratedClassUtils.get(FragmentTab2.class), null);
        tabHost.addTab(createSpec(TAB3, getString(R.string.tab_3), getString(R.string.icon_font_tab_schedule)), GeneratedClassUtils.get(FragmentTab3.class), null);
        tabHost.addTab(createSpec(TAB4, getString(R.string.tab_4), getString(R.string.icon_font_tab_my)), GeneratedClassUtils.get(FragmentTab4.class), null);
        // 设置Tab按钮的背景
//        tabHost.getTabWidget().setBackgroundResource(R.color.color_00bcd4);

    }


    /**
     * TabHost lable显示
     *
     * @param tag
     * @param label
     * @param label_icon
     * @return
     */
    private TabHost.TabSpec createSpec(String tag, String label, String label_icon) {
        View spec = View.inflate(this, R.layout.view_tab_indicator, null);
        TextView title = (TextView) spec.findViewById(R.id.tv_tab);
        title.setText(label);

        TextView title_icon = (TextView) spec.findViewById(R.id.tv_tab_icon);
        title_icon.setText(label_icon);
        return tabHost.newTabSpec(tag).setIndicator(spec);
    }
}
